package com.baizhi.service.impl;

import com.baizhi.annotation.AddCacheAnnotation;
import com.baizhi.dao.LogDao;
import com.baizhi.entity.Log;
import com.baizhi.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LogServiceImpl implements LogService {
    @Autowired(required = false)
    private LogDao logDao;

   /* @Override
    public Map selectAllByPageLog(int page, int limit, String logContent, String logType) {
        int offset=(page-1)*limit;
        if(logContent!=null&&!logContent.equals("")){
            logContent="%"+logContent+"%";

        }else{
            logContent=null;

        }
        if(logType!=null&&!logType.equals("")){
            logType="%"+logType+"%";
        }else{
            logType=null;
        }
        List<Log> list=logDao.selectAllByPageLog(offset,limit,logContent,logType);
        int count=logDao.selectCountLog(logContent,logType);
        Map map=new HashMap();
        map.put("data",list);
        map.put("count",count);
        map.put("code",0);
        map.put("msg","");

        return map;
    }*/


    @Override
    @AddCacheAnnotation
    public Map selectAllByPageLog(int page, int limit, String logType) {
        int offset=(page-1)*limit;
        /*if(logContent!=null&&!logContent.equals("")){
            logContent="%"+logContent+"%";

        }else{
            logContent=null;

        }*/
        if(logType!=null&&!logType.equals("")){
            logType="%"+logType+"%";
        }else{
            logType=null;
        }
        List<Log> list=logDao.selectAllByPageLog(offset,limit,logType);
        int count=logDao.selectCountLog(logType);
        Map map=new HashMap();
        map.put("data",list);
        map.put("count",count);
        map.put("code",0);
        map.put("msg","");

        return map;
    }
}
